/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package evidence.model.modeloveTridy;

import evidence.model.pomocneTridy.Time;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.poi.hssf.usermodel.HSSFRow;

/**
 *
 * @author Protheo
 */
public class DenniZaznam implements Serializable, IDenniZaznam  {
    public static final long serialVersionUID = 1;
    public static final Integer PROP_POC = 0;
    public static final Integer PROP_KON = 1;
    public static final Integer PROP_TYP = 2;
    public static final Integer PROP_KLI = 3;
    public static final Integer PROP_DOP = 4;
    public static final Integer PROP_PRE = 5;
    public static final Integer PROP_NEP = 6;
    public static final Integer PROP_UKO = 7;

    private Time pocatek;
    private Time konec;
    private String typ;
    private String klient;
    private String ukon;
    private Integer doparava;
    private Boolean prestavka;
    private String nepritomnost;

    public DenniZaznam(Time pocatek, Time konec, String typ, String klient, String ukon, Integer doparava, Boolean prestavka, String nepritomnost) {
        this.pocatek = pocatek;
        this.konec = konec;
        this.typ = typ;
        this.klient = klient;
        this.ukon = ukon;
        this.doparava = doparava;
        this.prestavka = prestavka;
        this.nepritomnost = nepritomnost;
    }

    public Integer getDoparava() {
        return doparava;
    }

    public String getKlient() {
        return klient;
    }

    public Time getKonec() {
        return konec;
    }

    public Time getPocatek() {
        return pocatek;
    }

    public String getTyp() {
        return typ;
    }

    public String getUkon() {
        return ukon;
    }

    public Double getDelka(){
        return this.konec.odectiCas(this.pocatek);
    }

    public Boolean isPrestavka() {
        return prestavka;
    }

    public String getNepritomnost() {
        return nepritomnost;
    }

    public void setProp(Map<Integer, Object> prop){
        for (Iterator<Integer> it = prop.keySet().iterator(); it.hasNext();) {
            Integer integer = it.next();
            switch (integer) {
                case 0: {
                    this.pocatek = (Time) prop.get(integer);
                }
                break;
                case 1: {
                    this.konec = (Time) prop.get(integer);
                }
                break;
                case 2: {
                    this.typ = (String) prop.get(integer);
                }
                break;
                case 3: {
                    this.klient = (String) prop.get(integer);
                }
                break;
                case 4: {
                    this.doparava = (Integer) prop.get(integer);
                }
                break;
                case 5: {
                    this.prestavka = (Boolean) prop.get(integer);
                }
                break;
                case 6: {
                    this.nepritomnost = (String) prop.get(integer);
                }
                break;
                case 7: {
                    this.ukon = (String) prop.get(integer);
                }
                break;
                default:
            }
        }
    }

    public List<Object> getData(){
        List<Object> pom = new ArrayList<Object>();
        pom.add(this.pocatek.toString());
        pom.add(this.prestavka());
        pom.add(this.konec.toString());
        pom.add(this.typ);
        pom.add(this.klient);
        pom.add(this.ukon);
        pom.add(this.doparava);
        pom.add(this.nepritomnost);
        return pom;
    }

    public String prestavka(){
        if (this.prestavka){
            if (true){
                return this.konec.toString()+" - "+this.konec.prictiCas(0, 30).toString();
            } else {
                return "";
            }
        }
        return "";
    }

    public void export(HSSFRow row){
        if(this.klient.toLowerCase().equals("dovolená")){
            row.getCell(6).setCellValue(this.klient);
            row.getCell(7).setCellValue(this.ukon);
            return;
        }
        row.getCell(1).setCellValue(this.pocatek.toString());
        row.getCell(2).setCellValue(this.prestavka());
        row.getCell(3).setCellValue(this.konec.toString());
        row.getCell(4).setCellValue(this.typ);
        row.getCell(5).setCellValue(this.getDelka());
        row.getCell(6).setCellValue(this.klient);
        row.getCell(7).setCellValue(this.ukon);
        if (this.doparava != 0){
            row.getCell(8).setCellValue(this.doparava);
        }
        row.getCell(9).setCellValue(this.nepritomnost);
    }
}
